package cn.classTest.mall.service.impl;

import cn.classTest.mall.domain.Goods;
import cn.classTest.mall.mapper.GoodsMapper;
import cn.classTest.mall.query.QueryObject;
import cn.classTest.mall.service.GoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public PageInfo<Goods> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Goods> goods = goodsMapper.selectAll();
        PageInfo<Goods> pageInfo = new PageInfo<>(goods);
        return pageInfo;
    }
    @Override
    public List<Goods> selectAll() {
        return goodsMapper.selectAll();
    }
    @Override
    public Goods selectOne(Long id) {
        return goodsMapper.selectOne(id);
    }

    @Override
    public void saveOrUpdate(Goods goods) {
        if (goods.getId() == null) {
            goodsMapper.save(goods);
        } else {
            goodsMapper.update(goods);
        }
    }
}
